package com.example.qxapp.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.qxapp.Bean.User;
import com.example.qxapp.MainActivity;
import com.example.qxapp.R;

import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

public class dlActivity extends AppCompatActivity {
    private EditText username,password;
    private Button dl;
    private TextView zc;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dl);
        init();

        dl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                User user=new User();
                user.setUsername(username.getText().toString().trim());
                user.setPassword(password.getText().toString().trim());
                user.login(new SaveListener<User>() {
                    @Override
                    public void done(User u, BmobException e) {
                        if (u!=null){
                            Toast.makeText(dlActivity.this,"登录成功，马上跳转",Toast.LENGTH_SHORT).show();
                            startActivity(new Intent(dlActivity.this, MainActivity.class));
                        }
                        else {
                            Toast.makeText(dlActivity.this,"账号或密码错误",Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            }
        });
        zc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(dlActivity.this, zcActivity.class));
            }
        });
    }
    private void init(){
        username=findViewById(R.id.username);
        password=findViewById(R.id.password);
        dl=findViewById(R.id.dl);
        zc=findViewById(R.id.zc);
    }
}
